/*
 * Winery.cpp
 *
 *  Created on: Apr 23, 2010
 *      Author: Sequoyha
 */
#include "Winery.h"

int Winery::totalWineries = 0;

//CONSTRUCTORS-----------------------------------------------------------------
Winery::Winery():wineryName(""),wineryNumber(0),
				current(),fromCanyonVilla(0), numberOfWines(0),
				wineInStock() {}
Winery::Winery(string name, int wNum, distFromHere fromCurrent,
		float fromCV, int numWines, wines stock)
		:wineryName(name),wineryNumber(wNum),
		current(fromCurrent),fromCanyonVilla(fromCV), numberOfWines(numWines),
		wineInStock(stock){}
//END CONSTRUCTORS-------------------------------------------------------------

//SETTERS----------------------------------------------------------------------
void Winery::setWineryName(string name){wineryName = name;}
void Winery::setWineryNumber(int wNum){wineryNumber = wNum;}
void Winery::setDistances(distFromHere input)
{
	for(unsigned int i = 0; i < input.size(); i++)
	{current.push_back(input[i]);}
}
void Winery::setDistanceFromCV(float fromCV){fromCanyonVilla = fromCV;}
void Winery::setNumberOfWines(int numWines){numberOfWines = numWines;}
void Winery::setStock(wines stock){wineInStock = stock;}
void Winery::addNewWine(WineInfo newWine){wineInStock.push_back(newWine);}
void Winery::changePricing()
{
	int wineToChange;
	float newPrice;
	//OUTPUT/INPUT
	PrintWines();
	cout << "Which Wine do you wish to edit pricing for?: ";
	wineToChange = MenuInput(this->getNumberOfWines());

	//FINDING WINE TO CHANGE PRICE FOR
    w = wineInStock.begin();
	for(int i = 0; i < wineToChange-1; i++)
	{
		w++;
	}
	cout << "Enter the new price: ";
	cin >> newPrice;
	//CHANGING PRICING
	w->setPrice(newPrice);

}
//END SETTERS---------------------------------------------------------------

//GETTERS-------------------------------------------------------------------
string Winery::getWineryName(){return wineryName;}
int Winery::getWineryNumber(){return wineryNumber;}
distFromHere Winery::getDistances(){return current;}
float Winery::getDistanceFromCV(){return fromCanyonVilla;}
int Winery::getNumberOfWines(){return numberOfWines;}
wines Winery::getStock(){return wineInStock;}
int Winery::getCount(){return totalWineries;}
float Winery::getClosestWinery()
{
	sortDistances();
	return closest;
}//Move to Winery as getClosest function;
//END GETTERS---------------------------------------------------------------

/***************************************************************************
 * SearchWines
 * Searches the vector of WineInfo to find a specific WineInfo object
 *
 * PreConditions:WineInfo vector must exist and have filled values
 *
 * PostConditions: an iterator of the vector position is returned to calling
 * function
 **************************************************************************/
vector <WineInfo>::iterator Winery::SearchWines(string srchValue)
{
	vector <WineInfo>::iterator found;
	found = find(wineInStock.begin(), wineInStock.end(),srchValue);
	return found;
}
/***************************************************************************
 * SortDistances
 * Sorts the Distances struct in order of closest to current Winery to
 * furthest from the current winery
 *
 *  reConditions:WineList vector must exist and have filled values
 *
 * PostConditions: Vector is sorted in distance order
 **************************************************************************/
void Winery::sortDistances(){sort(current.begin(), current.end());}

//Prints Distances vector to screen
void Winery::PrintDistances()
{
	//For loop to run through vector
	for(dfh = current.begin(); dfh < current.end(); dfh++)
	{
		//OUTPUT - Prints to screen
		cout << setw(20) << " " << dfh->getWinery() << " " ;
		cout << dfh->getFromCurrent() << " " << endl;
	}
}
void Winery::PrintWines()
{
	int i = 0; //position marker
	//For loop to run through vector
	for(w = wineInStock.begin(); w < wineInStock.end(); w++)
		{
			i++; //Increment position marker
			//OUTPUT - Prints to screen
			cout << setw(10) << " " << i << "  ";
			cout << setw(30) << w->getWineName();
			cout << setw(6)<< w->getVintage() << " $" ;
			cout << setw(8) << fixed << setprecision(2);
			cout << w->getPrice() << endl;
		}
}
//OPERATORS--------------------------------------------------------------------

//Compares Winery objects to sort in order of distance from Canyon Villa
bool Winery::operator<(const Winery &obj)const
{
	if(this->fromCanyonVilla < obj.fromCanyonVilla)
		return true;
	else{return false;}
}
//Compares Winery objects to check if an object is a match
bool Winery::operator==(int srchItem)const
{
	if(this->wineryNumber == srchItem)
	{return true;}
	else{return false;}
}

//COPY CONSTRUCTOR FOR ASSIGNMENT
Winery::Winery(const Winery &obj)
{
	wineryName = obj.wineryName;
	wineryNumber = obj.wineryNumber;
	current = obj.current;
	distFromHere::iterator dfh;
	fromCanyonVilla = obj.fromCanyonVilla;
    numberOfWines = obj.numberOfWines;
    wineInStock = obj.wineInStock;//Maybe set to 10 since 10 is the max
	wines::iterator w;
    wineryCount = obj.wineryCount;
    closest = obj.closest;
}
//END OPERATORS----------------------------------------------------------------
